package fun.qu_an.minecraft.mini_games_helper.client.mixin.sodium;

import fun.qu_an.minecraft.mini_games_helper.client.handle.ForceOptionHelperSodium;
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.options.control.Control;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.text.TranslatableTextContent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(SodiumOptionsGUI.class)
public class SodiumOptionsGUIMixin {
	@SuppressWarnings("unchecked")
	@Redirect(method = "rebuildGUIOptions()V", remap = false,
	at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/options/control/Control;createElement(Lme/jellysquid/mods/sodium/client/util/Dim2i;)Lme/jellysquid/mods/sodium/client/gui/options/control/ControlElement;"))
	private <T> ControlElement<T> onCreateElement(Control<T> instance, Dim2i dim2i) {
		Option<T> option = instance.getOption();
		Option<?> forced = ForceOptionHelperSodium.get(((TranslatableTextContent) option.getName().getContent()).getKey());
		if (forced != null){
			return (ControlElement<T>) new ControlElement<>(forced, dim2i);
		} else {
			return instance.createElement(dim2i);
		}
	}
}
